home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ELECTRON / PCB_DESI / 1540.ZIP / PCBCA110.ZIP / ALLOC.C next >
C/C++ Source or Header  |  1990-11-18  |  697b  |  31 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #ifdef VMS
  5. #define far
  6. #else
  7. #include <dos.h>
  8. #endif
  9.  
  10. char far *Alloc( long );
  11. void Nomem( void );
  12.  
  13. char far *Alloc ( x ) /* allocate x bytes of far memory */
  14.     long x;
  15.     {
  16.     union REGS regs;
  17.  
  18.     regs.h.ah = 0x48; /* allocate memory dos call */
  19.     x = (x+15)>>4; /* get number of paragraphs to allocate */
  20.     regs.x.bx = (int)x;
  21.     intdos( ®s, ®s ); /* call dos; request memory */
  22.     if (regs.x.cflag) /* memory allocation error */
  23.         Nomem();
  24.     return( (char far *)((long)regs.x.ax<<16) ); /* make a far pointer */
  25.     }
  26.  
  27. void Nomem () { /* a memory allocation request has failed */
  28.     fprintf( stderr, "out of memory\n" );
  29.     exit( -1 );
  30.     }
  31.